package com.google.code.swingonfire.showcase.utility;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import com.google.code.eventsonfire.Events;
import com.google.code.eventsonfire.awt.AWTEvents;
import com.google.code.eventsonfire.swing.SwingEventHandler;
import com.google.code.swingonfire.border.ShadowBorder;
import com.google.code.swingonfire.component.JBorderPanel;
import com.google.code.swingonfire.layout.GBC;
import com.google.code.swingonfire.showcase.TitlePanel;
import com.google.code.swingonfire.utility.WindowUtils;

import static com.google.code.swingonfire.builder.JComponentBuilders.*;

public class WindowUtilsShowcase extends JPanel
{

    private static final long serialVersionUID = -2206822028563237612L;

    public WindowUtilsShowcase()
    {
        super(new BorderLayout());

        JPanel panel = panelBuilder().layout(new GridBagLayout()).build();
        panel.setBackground(Color.WHITE);
        panel.setOpaque(true);
        GBC gbc = new GBC(1, 5);

        panel.add(
            Events.bind(buttonBuilder().text("Enter Fullscreen").listener("enterFullscreen", AWTEvents.fireOnAction())
                .build(), this), gbc);

        panel.add(
            Events.bind(buttonBuilder().text("Exit Fullscreen").listener("exitFullscreen", AWTEvents.fireOnAction())
                .build(), this), gbc.next());

        add(new JBorderPanel(new TitlePanel("WindowUtils", "A utility class for Windows and Frames"),
            ShadowBorder.create()), BorderLayout.NORTH);
        add(new JBorderPanel(panel, ShadowBorder.create()), BorderLayout.CENTER);
    }

    @SwingEventHandler(event = ActionEvent.class, eachTag = "enterFullscreen")
    public void onEnterFullscreen()
    {
        System.out.println("Enter Fullscreen");
        WindowUtils.enterFullscreen(SwingUtilities.getWindowAncestor(this));
    }

    @SwingEventHandler(event = ActionEvent.class, eachTag = "exitFullscreen")
    public void onExitFullscreen()
    {
        System.out.println("Exit Fullscreen");
        WindowUtils.exitFullscreen(SwingUtilities.getWindowAncestor(this));
    }

}
